package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdminPreid;
import com.ruoyi.system.service.IAdminPreidService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课时Controller
 * 
 * @author ruoyi
 * @date 2020-06-16
 */
@Controller
@RequestMapping("/system/preid")
public class AdminPreidController extends BaseController
{
    private String prefix = "system/preid";

    @Autowired
    private IAdminPreidService adminPreidService;

    @RequiresPermissions("system:preid:view")
    @GetMapping()
    public String preid()
    {
        return prefix + "/preid";
    }

    /**
     * 查询课时列表
     */
    @RequiresPermissions("system:preid:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdminPreid adminPreid)
    {
        startPage();
        List<AdminPreid> list = adminPreidService.selectAdminPreidList(adminPreid);
        return getDataTable(list);
    }

    /**
     * 导出课时列表
     */
    @RequiresPermissions("system:preid:export")
    @Log(title = "课时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdminPreid adminPreid)
    {
        List<AdminPreid> list = adminPreidService.selectAdminPreidList(adminPreid);
        ExcelUtil<AdminPreid> util = new ExcelUtil<AdminPreid>(AdminPreid.class);
        return util.exportExcel(list, "preid");
    }

    /**
     * 新增课时
     */
    @GetMapping("/add/{subjectId}")
    public String add(@PathVariable("subjectId") Long subjectId, ModelMap mmap)
    {
        mmap.put("subjectId", subjectId);
        return prefix + "/add";
    }

    /**
     * 新增保存课时
     */
    @RequiresPermissions("system:preid:add")
    @Log(title = "课时", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdminPreid adminPreid)
    {
        return toAjax(adminPreidService.insertAdminPreid(adminPreid));
    }

    /**
     * 修改课时
     */
    @GetMapping("/edit/{preidId}")
    public String edit(@PathVariable("preidId") Long preidId, ModelMap mmap)
    {
        AdminPreid adminPreid = adminPreidService.selectAdminPreidById(preidId);
        mmap.put("adminPreid", adminPreid);
        return prefix + "/edit";
    }

    /**
     * 修改保存课时
     */
    @RequiresPermissions("system:preid:edit")
    @Log(title = "课时", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdminPreid adminPreid)
    {
        return toAjax(adminPreidService.updateAdminPreid(adminPreid));
    }

    /**
     * 删除课时
     */
    @RequiresPermissions("system:preid:remove")
    @Log(title = "课时", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adminPreidService.deleteAdminPreidByIds(ids));
    }

    /**
     * 查询课件详细
     */
    @RequiresPermissions("system:preid:list")
    @GetMapping("/detail/{preidId}")
    public String detail(@PathVariable("preidId") Long preidId, ModelMap mmap)
    {
      mmap.put("preidId", preidId);
      return "/system/course/course";
    }
}
